package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Video;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author wulei
 * @Date 2018/9/30
 */

public class HookMonitorAdapter extends BaseAdapter {
    private List<Video> dataList;
    private Context context;

    public HookMonitorAdapter(Context context, List<Video> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MonitorViewHolder holder;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.item_hook_video, null);
            holder = new MonitorViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (MonitorViewHolder) convertView.getTag();
        }
        holder.bindData(position);
        return convertView;
    }

    public class MonitorViewHolder extends RecyclerAdapter.BaseViewHolder<Video>
    {
        @BindView(R.id.video_name)
        HXTextView videoName;
        @BindView(R.id.play_img)
        ImageView playImg;

        public MonitorViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(final int position) {
            Video video = dataList.get(position);
            videoName.setText(video.getName());
            if(video.getIsOnline() == 1){
                playImg.setImageResource(R.mipmap.monitor_realtime_n);
            }else{
                playImg.setImageResource(R.mipmap.monitor_realtime_e);
            }
        }
    }
}
